package com.punai.customer.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.core.domain.TreeBo;
import com.punai.common.utils.SecurityUtils;
import com.punai.customer.domain.CusMechanicalStaChapter;
import com.punai.customer.mapper.CusMechanicalStaChapterMapper;
import com.punai.customer.service.ICusMechanicalStaChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 机械章节Service业务层处理
 *
 * @author zxw_
 * @date 2023-02-02
 */
@Service
public class CusMechanicalStaChapterServiceImpl extends ServiceImpl<CusMechanicalStaChapterMapper,CusMechanicalStaChapter> implements ICusMechanicalStaChapterService
{
    @Autowired
    private CusMechanicalStaChapterMapper cusMechanicalStaChapterMapper;

    /**
     * 查询机械章节
     *
     * @param id 机械章节主键
     * @return 机械章节
     */
    @Override
    public CusMechanicalStaChapter selectCusMechanicalStaChapterById(String id)
    {
        return cusMechanicalStaChapterMapper.selectCusMechanicalStaChapterById(id);
    }

    /**
     * 查询机械章节列表
     *
     * @param cusMechanicalStaChapter 机械章节
     * @return 机械章节
     */
    @Override
    public List<CusMechanicalStaChapter> selectCusMechanicalStaChapterList(CusMechanicalStaChapter cusMechanicalStaChapter)
    {
        return cusMechanicalStaChapterMapper.selectCusMechanicalStaChapterList(cusMechanicalStaChapter);
    }

    /**
     * 新增机械章节
     *
     * @param cusMechanicalStaChapter 机械章节
     * @return 结果
     */
    @Override
    public int insertCusMechanicalStaChapter(CusMechanicalStaChapter cusMechanicalStaChapter)
    {
            return cusMechanicalStaChapterMapper.insert(cusMechanicalStaChapter);
    }

    /**
     * 修改机械章节
     *
     * @param cusMechanicalStaChapter 机械章节
     * @return 结果
     */
    @Override
    public int updateCusMechanicalStaChapter(CusMechanicalStaChapter cusMechanicalStaChapter)
    {
        return cusMechanicalStaChapterMapper.updateById(cusMechanicalStaChapter);
    }

    /**
     * 批量删除机械章节
     *
     * @param ids 需要删除的机械章节主键
     * @return 结果
     */
    @Override
    public int deleteCusMechanicalStaChapterByIds(String[] ids)
    {
        return cusMechanicalStaChapterMapper.deleteCusMechanicalStaChapterByIds(ids);
    }

    /**
     * 删除机械章节信息
     *
     * @param id 机械章节主键
     * @return 结果
     */
    @Override
    public int deleteCusMechanicalStaChapterById(String id)
    {
        return cusMechanicalStaChapterMapper.deleteCusMechanicalStaChapterById(id);
    }

    @Override
    public List<TreeBo> selectTreeData() {
        Long companyId = SecurityUtils.getCompanyId();
        List<CusMechanicalStaChapter> chapters = cusMechanicalStaChapterMapper.selectList(
                Wrappers.<CusMechanicalStaChapter>lambdaQuery()
                        .eq(CusMechanicalStaChapter::getCompanyId, companyId)
        );
        return TreeBo.convert(chapters);
    }
}
